/*
 */
package org.hook.showcase.concurrent.immutable;

import java.math.BigInteger;
import java.util.Arrays;

import net.jcip.annotations.Immutable;

/**
 * @author suwuqiang 2011-12-6
 */
@Immutable
public class OneValueCache {
	private final BigInteger lastNumber;
	private final BigInteger[] lastFactors;

	public OneValueCache(BigInteger i, BigInteger[] factors) {
		this.lastNumber = i;
		this.lastFactors = Arrays.copyOf(factors, factors.length);
	}

	public BigInteger[] getFactors(BigInteger i) {
		if (lastNumber == null || !lastNumber.equals(i))
			return null;
		else
			return Arrays.copyOf(this.lastFactors, this.lastFactors.length);
	}
}
